﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Site.Master.cs" company="Tobias Lekman">
//   Licensed under Microsoft Public License (Ms-PL). See lekman.codeplex.com/license for more information.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace LekmanCom
{
    using System;
    using System.Web.UI;

    /// <summary>
    /// Code behind for the site master page.
    /// </summary>
    public partial class SiteMaster : MasterPage
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the CSS class for the body.
        /// </summary>
        /// <value>
        /// The CSS class for the body.
        /// </value>
        public string BodyClass
        {
            get
            {
                return this.BodyTag.Attributes["class"];
            }

            set
            {
                this.BodyTag.Attributes["class"] = value;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
        /// </summary>
        /// <param name="e">
        /// The <see cref="T:System.EventArgs"/> object that contains the event data.
        /// </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
#if !DEBUG
            ValidateHostName();
#endif
        }

        /// <summary>
        /// Validates the name of the host by assuring that "www" is preprended.
        /// </summary>
        private void ValidateHostName()
        {
            if (!this.Request.Url.DnsSafeHost.StartsWith("www"))
            {
                this.Response.Redirect("http://www.lekman.com" + this.Request.Url.PathAndQuery);
            }
        }

        #endregion
    }
}